import { login } from '../../utils/asyncWx'
import request from '../../request/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  //获取信息
  async handleGetUserInfo (e) {
    //获取用户信息
    try {
      const { encryptedData, iv, rawData, signature } = e.detail

      // 获取小程序登录厚得code值
      const { code } = await login()
      // const code = '021xRW7i11b5Ev0uSC7i1SL48i1xRW7Q'
      const loginParams = { encryptedData, rawData, iv, signature, code }
      // console.log(loginParams);
      // const res = await request({ url: "/users/wxlogin", data: loginParams, method: "post" })
      const token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
      wx.setStorageSync('token', token)
      wx.navigateBack({
        delta: 1//返回上一层
      })

    } catch (error) {
      console.log(error);
    }
  }
})